serial_data = dlmread('res_hw2_serial') ;
[serial_data_n, serial_data_rows] = unique(serial_data(:,1)) ; %Remove duplicate lines
serial_newton_data = dlmread('res_hw2_serial_newton') ;
[serial_newton_data_n, serial_newton_data_rows] = unique(serial_newton_data(:,1)) ;
serial_data_tp = serial_data(serial_data_rows, 2) ;
serial_newton_data_tp = serial_newton_data(serial_newton_data_rows, 2) ;

serial_data_R = serial_data_n.^2 ./ serial_data_tp;
serial_newton_data_R = serial_newton_data_n.^2 ./ serial_newton_data_tp;

figure;
plot(serial_data_n, serial_data_R, '-or', ...
    serial_newton_data_n, serial_newton_data_R, '-*b');
title('R(n, p) for sequential programs');
xlabel('n') ;
ylabel('R(n, p)');
ylim([0 max(serial_newton_data_R)*1.3]) ;
legend('Sequential', 'Sequential with Newton');
legend boxoff;


pl_data = dlmread('res_hw2_pl');
pl_data_p = unique(pl_data(:, 1)) ; %all the unique elements in the first column
pl_data_n = unique(pl_data(:, 2)) ;
max_pl_data_n = max(pl_data_n) ;
pl_data_max_n = pl_data(pl_data(:, 2) == max_pl_data_n, :) ;%pl_data with rows in which n is maximum
pl_data_max_n_tp = pl_data_max_n(:, 3) ;
pl_data_max_n_R = max_pl_data_n^2 ./ pl_data_max_n_tp ;

figure;
plot(pl_data_p, pl_data_max_n_R, '-ob');
title('R(n, p) for parallel with n = 10000');
xlabel('p') ;
ylabel('R(n, p)');
ylim([0 max(pl_data_max_n_R)*1.3]) ;
legend('Parallel implementation');
legend boxoff;



pl_newton_data = dlmread('res_hw2_pl_newton');
pl_newton_data_p = unique(pl_newton_data(:, 1));
pl_newton_data_n = unique(pl_newton_data(:, 2));
max_pl_newton_data_n = max(pl_newton_data_n);
pl_newton_data_max_n = pl_newton_data(pl_newton_data(:, 2) == max_pl_newton_data_n, :) ;
pl_newton_data_max_n_tp = pl_newton_data_max_n(:, 3) ;
pl_newton_data_max_n_R = max_pl_newton_data_n^2 ./ pl_newton_data_max_n_tp ;


max_pl_data_n = 5000;
pl_data_max_n = pl_data(pl_data(:, 2) == max_pl_data_n, :) ;
pl_data_max_n_tp = pl_data_max_n(:, 3) ;
pl_data_max_n_R = max_pl_data_n^2 ./ pl_data_max_n_tp ;
max_pl_newton_data_n = 5000 ;
pl_newton_data_max_n = pl_newton_data(pl_newton_data(:, 2) == max_pl_newton_data_n, :) ;
pl_newton_data_max_n_tp = pl_newton_data_max_n(:, 3) ;
pl_newton_data_max_n_R = max_pl_newton_data_n^2 ./ pl_newton_data_max_n_tp ;

figure;
plot(pl_data_p, pl_data_max_n_R, '-ob',...
    pl_newton_data_p, pl_newton_data_max_n_R, '-*r');
title('R(n, p) for parallel with n = 5000');
xlabel('p') ;
ylabel('R(n, p)');
ylim([0 max(pl_newton_data_max_n_R)*1.3]) ;
legend('Parallel implementation', 'Parallel with Newton');
legend boxoff;
